# 请参阅 https://aka.ms/customizecontainer 以了解如何自定义调试容器，以及 Visual Studio 如何使用此 Dockerfile 生成映像以更快地进行调试。

# 根据将生成或运行容器的主机的操作系统，可能需要更改 FROM 语句中指定的映像。
# 有关详细信息，请参阅 https://aka.ms/containercompat

# 此阶段用于在快速模式(默认为调试配置)下从 VS 运行时
FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base
RUN sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list && \
    sed -i 's/security.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list && \
    apt-get update && \
    apt-get install -y --no-install-recommends libfontconfig1 && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*
WORKDIR /app
EXPOSE 9991


# 此阶段用于生成服务项目
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["iMES.WebApi/iMES.WebApi.csproj", "iMES.WebApi/"]
COPY ["iMES.Builder/iMES.Builder.csproj", "iMES.Builder/"]
COPY ["iMES.Core/iMES.Core.csproj", "iMES.Core/"]
COPY ["iMES.Entity/iMES.Entity.csproj", "iMES.Entity/"]
COPY ["iMES.Calendar/iMES.Calendar.csproj", "iMES.Calendar/"]
COPY ["iMES.Custom/iMES.Custom.csproj", "iMES.Custom/"]
COPY ["iMES.Cese/iMES.Cese.csproj", "iMES.Cese/"]
COPY ["iMES.Equip/iMES.Equip.csproj", "iMES.Equip/"]
COPY ["iMES.Inventory/iMES.Inventory.csproj", "iMES.Inventory/"]
COPY ["iMes.Mass/iMES.Mass.csproj", "iMes.Mass/"]
COPY ["iMES.Quality/iMES.Quality.csproj", "iMES.Quality/"]
COPY ["iMES.Report/iMES.Report.csproj", "iMES.Report/"]
COPY ["IMES.SheBei/IMES.SheBei.csproj", "IMES.SheBei/"]
COPY ["iMES.System/iMES.System.csproj", "iMES.System/"]
COPY ["iMES.Tools/iMES.Tools.csproj", "iMES.Tools/"]
COPY ["iMES.Warehouse/iMES.Warehouse.csproj", "iMES.Warehouse/"]
COPY ["iMES.WorkManShip/iMES.WorkManShip.csproj", "iMES.WorkManShip/"]
RUN dotnet restore "./iMES.WebApi/iMES.WebApi.csproj"
COPY . .
WORKDIR "/src/iMES.WebApi"
RUN dotnet build "./iMES.WebApi.csproj" -c %BUILD_CONFIGURATION% -o /app/build

# 此阶段用于发布要复制到最终阶段的服务项目
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./iMES.WebApi.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

# 此阶段在生产中使用，或在常规模式下从 VS 运行时使用(在不使用调试配置时为默认值)
FROM base AS final
WORKDIR /app
ENV ASPNETCORE_ENVIRONMENT=Development
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "iMES.WebApi.dll"]